package mplayer.servlets;

import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import javax.servlet.FilterChain;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import mplayer.dao.HibernateUtil;
import mplayer.dao.UserDao;
import mplayer.entity.User;

/**
 * Servlet implementation class ManageLogin
 */
@WebServlet("/ManageLogin")
public class ManageLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private  String userId;
	private  String password;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ManageLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		List<User> list;
		UserDao userDao = new  UserDao();
		userId = request.getParameter("userid");
		password=Utility.convertToMD5(request.getParameter("password"));
		list=userDao.getUserByLoginPw(userId, password);
				 	
		if (list.isEmpty()) {
		
			response.sendRedirect("index.jsp");
			return;
		} else {
			RequestDispatcher dispatcher = request.getRequestDispatcher("home.jsp");
			dispatcher.forward(request, response);
			return;
		}
	
	
	}
	



}
